#   Copyright 2013 Stacy Doss stacy.doss@gmail.com
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

package DIME::Data;

use strict;
use warnings;

use DIME::Data::Config;

our $VERSION = '0.01';

sub new {

	my $class  = shift;
	my $app    = shift;
		
	my $T = {
        application => $app,
	};
		
	bless $T, $class;

    $T->{config} = new DIME::Data::Config($T);

	return $T;
}



sub getApplication {
    my $self = shift;

    unless ($self->{application}) {
        u_fatal(1, 'No application defined')        
    }
    
    print "$self->{application}\n";
    
    return $self->{application};
}



sub getData {
    my $self = shift;

    return $self->{data};
}



sub getRoot {
    my $self = shift;

    return $self->{data};
}



sub getOption {
    my $self   = shift;
    my $option = shift;

    return $self->{config}->getOption($option);
}



sub loadConfig {
    my $self = shift;
    
    $self->{config}->load();
    return $self->{config};
}



sub saveConfig {
    my $self = shift;
    
    $self->{config}->save();    
}



sub setData {
    my $self = shift;
    my $data = shift;

    unless ($data) {
        print STDERR "No data root given. Cannot set DATA.\n";    
    }
    
    if ($self->{data}) {
        delete $self->{data};
    }

    $self->{data} = $data;
    
    print "Set data to $self->{data}\n";
    
    return $self->{data};
}



sub toggleConfig {
    my $self = shift;
    my $name = shift;

    return $self->{config}->toggleView($name);
}



1;

# End of DIME::Data
